package com.yiwei.jmx.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.jmx.R;
import com.yiwei.jmx.api.model.MyCertificationModel;
import com.yiwei.jmx.constant.Const;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class IdentityOneAdapter extends ItemAdapter<MyCertificationModel.Data.Basic, IdentityOneAdapter.DefaultHolder> {


    private int res[][] = {
//           0： 身份认证
            {R.mipmap.img_realname_no, R.mipmap.img_realname_ing, R.mipmap.img_realname_yes},
//           1： 人脸识别
            {R.mipmap.img_face_no, R.mipmap.img_face_ing, R.mipmap.img_face_yes},
//           2： 银行卡认证
            {R.mipmap.img_bankcard_no, R.mipmap.img_bankcard_ing, R.mipmap.img_bankcard_yes},
//           3：通讯录认证
            {R.mipmap.img_tongxunlu_no, R.mipmap.img_tongxunlu_ing, R.mipmap.img_tongxunlu_yes},
//            4：运营商认证
            {R.mipmap.img_yunyin_no, R.mipmap.img_yunyin_ing, R.mipmap.img_yunyin_yes},
//            5：淘宝认证
            {R.mipmap.img_taobao_no, R.mipmap.img_taobao_ing, R.mipmap.img_taobao_yes},
//            6：京东认证
            {R.mipmap.img_jd_no, R.mipmap.img_jd_ing, R.mipmap.img_jd_yes},
//            7：芝麻信用认证
            {R.mipmap.img_face_detect_no, R.mipmap.img_face_detect_ing, R.mipmap.img_face_detect_yes},
//            8：支付宝认证
            {R.mipmap.img_face_detect_no, R.mipmap.img_face_detect_ing, R.mipmap.img_face_detect_yes},
//            9：学历认证
            {R.mipmap.img_xuexin_no, R.mipmap.img_xuexin_ing, R.mipmap.img_xuexin_yes},
//            10：社保认证
            {R.mipmap.img_socialsecurity_no, R.mipmap.img_socialsecurity_ing, R.mipmap.img_socialsecurity_yes},
//            11：公积金认证
            {R.mipmap.img_housefund_no, R.mipmap.img_housefund_ing, R.mipmap.img_housefund_yes},
//            12：房产认证
            {R.mipmap.img_house_no, R.mipmap.img_house_ing, R.mipmap.img_house_yes},
//            13：车产认证
            {R.mipmap.img_car_no, R.mipmap.img_car_ing, R.mipmap.img_car_yes},
//            14：工作证明
            {R.mipmap.img_work_no, R.mipmap.img_work_ing, R.mipmap.img_work_yes},
//            15：收入认证
            {R.mipmap.img_income_no, R.mipmap.img_income_ing, R.mipmap.img_income_yes},
    };
    private Context context;

    public IdentityOneAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_identity_center, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        MyCertificationModel.Data.Basic item = getItem(position);
        if (item.iscert.equals("3")) {
            holder.imgSign.setVisibility(View.VISIBLE);
        } else {
            holder.imgSign.setVisibility(View.GONE);
        }

        holder.txtContent.setText(item.name);

        int typePoi = 0;
//        -1：认证失败，0 - 未认证、 1 - 已认证、2 - 认证中，3 - 需要重新认证
        switch (item.remark) {
            case Const.IdentityType.realname:
                typePoi = 0;
                break;
            case Const.IdentityType.face:
                typePoi = 1;
                break;
            case Const.IdentityType.bankcard:
                typePoi = 2;
                break;
            case Const.IdentityType.tongxunlu:
            case Const.IdentityType.contacts:
                typePoi = 3;
                break;
            case Const.IdentityType.yunyin:
                typePoi = 4;
                break;
            case Const.IdentityType.taobao:
                typePoi = 5;
                break;
            case Const.IdentityType.jd:
                typePoi = 6;
                break;
            case Const.IdentityType.face_detect:
                typePoi = 7;
                break;
            case Const.IdentityType.zhifubao:
                typePoi = 8;
                break;
            case Const.IdentityType.xuexin:
                typePoi = 9;
                break;
            case Const.IdentityType.socialsecurity:
                typePoi = 10;
                break;
            case Const.IdentityType.housefund:
                typePoi = 11;
                break;
            case Const.IdentityType.house:
                typePoi = 12;
                break;
            case Const.IdentityType.car:
                typePoi = 13;
                break;
            case Const.IdentityType.work:
                typePoi = 14;
                break;
            case Const.IdentityType.income:
                typePoi = 15;
                break;
        }


        //        -1：认证失败，0 - 未认证、 1 - 已认证、2 - 认证中，3 - 需要重新认证
        if (item.iscert.equals("-1")) {
            holder.txtContent.setTextColor(0xffBBBBBB);
            holder.txtDesc.setTextColor(0xffFF2740);
            holder.txtDesc.setText("认证失败，重新认证");
            Glide.with(context).load(res[typePoi][0]).into(holder.imgIcon);
        } else if (item.iscert.equals("0")) {
            holder.txtContent.setTextColor(0xffBBBBBB);
            holder.txtDesc.setTextColor(0xffCCCCCC);
            holder.txtDesc.setText("最高可获" + item.rewards + "智信分");

            Glide.with(context).load(res[typePoi][0]).into(holder.imgIcon);
        } else if (item.iscert.equals("1") || item.iscert.equals("3")) {
            holder.txtContent.setTextColor(0xff000000);
            holder.txtDesc.setTextColor(0xff566F8E);
            holder.txtDesc.setText("已获" + item.rewards + "智信分");
            Glide.with(context).load(res[typePoi][2]).into(holder.imgIcon);
        } else if (item.iscert.equals("2")) {
            holder.txtContent.setTextColor(0xff000000);
            holder.txtDesc.setTextColor(0xff0072FF);
            holder.txtDesc.setText("认证中");
            Glide.with(context).load(res[typePoi][1]).into(holder.imgIcon);
        }


        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClick(item.iscert, item.remark);
                }
            }
        });
    }


    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.txt_desc)
        TextView txtDesc;
        @BindView(R.id.layout_total)
        LinearLayout layoutTotal;
        @BindView(R.id.img_sign)
        ImageView imgSign;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    private IdentityTypsInterface onChooseListener;

    public void setOnChooseListener(IdentityTypsInterface onChooseListener) {
        this.onChooseListener = onChooseListener;
    }
}
